package matchers;

import java.util.Set;

import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLOntology;

public class StructureNeighborhood {
        private OWLClass classA, classB;
        private OWLOntology ontoA, ontoB;

        public StructureNeighborhood(OWLClass classA, OWLClass classB, OWLOntology ontoA, OWLOntology ontoB) {
                super();
                this.classA = classA;
                this.classB = classB;
                this.ontoA = ontoA;
                this.ontoB = ontoB;
        }

        public double getSimilarity(){
    		double subclass =  similaritySubClasses();
    		double superclass =  similaritySuperClasses();
            
    		return (0.8 * subclass) + (0.2 * superclass);
            
            
            
//                for (OWLAnnotationProperty an : ontoA.getAnnotationPropertiesInSignature()) {
//					System.out.println(an.toString());
//				}
//                System.out.println("prop: " + ontoA.getAnnotationPropertiesInSignature().size());
//                System.out.println("prop class: " + classA.getDataPropertiesInSignature().size());
//                System.out.println("type class: " + classA.getDatatypesInSignature().size());
        }

		private double similaritySuperClasses() {
			Set<OWLClassExpression> superClassesA = classA.getSuperClasses(ontoA);
            Set<OWLClassExpression> superClassesB = classB.getSuperClasses(ontoB);

            if (superClassesA.size() == superClassesB.size()) {
            	return 1;
			} else if (superClassesA.size() > superClassesB.size()) {
				return 1 - ((superClassesA.size() - superClassesB.size()) / (superClassesA.size() + superClassesB.size()));
			} else {
				return 1 - ((superClassesB.size() - superClassesA.size()) / (superClassesA.size() + superClassesB.size()));
			}
		}

		private double similaritySubClasses() {
			Set<OWLClassExpression> subClassesA = classA.getSubClasses(ontoA);
            Set<OWLClassExpression> subClassesB = classB.getSubClasses(ontoB);
            
            if (subClassesA.size() == subClassesB.size()) {
            	return 1;
			} else if (subClassesA.size() > subClassesB.size()) {
				return 1 - ((subClassesA.size() - subClassesB.size()) / (subClassesA.size() + subClassesB.size()));
			} else {
				return 1 - ((subClassesB.size() - subClassesA.size()) / (subClassesA.size() + subClassesB.size()));
			}
		}
        
        
}
